Ext.define('AmpleHarvest.objects.files.cToolbar',
{
	extend				: 'Ext.toolbar.Toolbar',
	alias				: 'widget.ampleharvest-objects-files-ctoolbar',
	requires			:
	[
			'Ext.data.TreeStore', 'Ext.button.Button'
	],

	initComponent		: function()
	{
		var obj_This = this;

		this.m_obj_Download = Ext.create("Ext.button.Button",
		{
			text		: 'Download',
			disabled	: true,
			iconCls		: "toolbar-article-navigation-files-download",
			handler		: function(rowIndex)
			{
				var recSelMod = this.up('ampleharvest-objects-files-cfiles').getSelectionModel();

				var arr_recs = recSelMod.getSelection();
				Ext.Array.each(arr_recs, function(obj, index, arr_all)
				{
					var obj_container = obj.get('container');
					var obj_Dowload = obj_container.download;
					if (!obj_Dowload)
					{
						console.log('no download available');
					}
					m_obj_AmpleHarvest_ViewPort
							.fireEvent(
									AmpleHarvest.eventHandler.cWindowEvents.C_STR_EVENT_DOWNLOAD,
									obj_Dowload.serverId, obj_Dowload.id
							);
				}
				);
			}

		}
		);

		this.m_obj_Open = Ext.create("Ext.button.Button",
		{
			text		: 'View',
			disabled	: true,
			iconCls		: 'toolbar-article-navigation-files-view',
			handler		: function(rowIndex)
			{
				var recs = this.up('ampleharvest-objects-files-cfiles').getSelectionModel()
						.getSelection();
				Ext.Array.each(recs, function(obj, index, arr_all)
				{
					var obj_container = obj.get('container');
					var obj_Link = obj_container.htmlDisplay;

					m_obj_AmpleHarvest_ViewPort
					.fireEvent(
							AmpleHarvest.eventHandler.cWindowEvents.C_STR_EVENT_ARTICLE_OPEN,
							obj_Link.id, ''
					);
				}
				);
			}
		}
		);

		this.m_obj_Info = Ext.create("Ext.button.Button",
		{
			text		: 'Info',
			disabled	: true,
			iconCls		: 'toolbar-article-navigation-files-info',
			handler		: function(rowIndex)
			{
				var recs = this.up('ampleharvest-objects-files-cfiles').getSelectionModel()
						.getSelection();
				Ext.Array.each(recs, function(obj, index, arr_all)
				{
					var obj_container = obj.get('container');

					m_obj_AmpleHarvest_ViewPort
							.fireEvent(
									AmpleHarvest.eventHandler.cWindowEvents.C_STR_EVENT_OPEN_FILE_INFO,
									obj.get('text'), obj_container.metadata
							);
				}
				);
			},
			scope		: this
		}
		);

		this.callParent();

		this.add(this.m_obj_Download);
		this.add(this.m_obj_Open);
		this.add(this.m_obj_Info);
	},

	set_ButtonStatus	: function(obj_Button, bool_Status)
	{
		if (bool_Status)
		{
			obj_Button.enable();
		}
		else
		{
			obj_Button.disable();
		}
	},

	set_Download		: function(bool_Status)
	{
		this.set_ButtonStatus(this.m_obj_Download, bool_Status);
	},
	set_Open			: function(bool_Status)
	{
		this.set_ButtonStatus(this.m_obj_Open, bool_Status);
	},
	set_Info			: function(bool_Status)
	{
		this.set_ButtonStatus(this.m_obj_Info, bool_Status);
	}
}
);